package response

import (
	"MoSkeleton/framework/core/dto/request"
	"MoSkeleton/framework/core/motypes"
	"MoSkeleton/framework/utils"
)

type PageResult struct {
	Rows     interface{} `json:"rows"`
	Total    int64       `json:"total"`
	Page     int         `json:"page"`
	PageSize int         `json:"pageSize"`
}

func NewFromPageInfo(pageInfo *request.PageInfo) *PageResult {
	pageResult := new(PageResult)
	if err := utils.CopyStruct(pageResult, pageInfo); err != nil {
		return nil
	}
	return pageResult
}

func NewFromPageInfoAndData(pageInfo *request.PageInfo, rows any, total int64) *PageResult {
	pageResult := NewFromPageInfo(pageInfo)
	pageResult.Rows = rows
	pageResult.Total = total
	return pageResult
}

type ModelResp struct {
	ID        uint64          `json:"id,string" form:"id,string"`
	CreatedAt *motypes.MoTime `json:"createdAt,omitempty" form:"createdAt"`
	UpdatedAt *motypes.MoTime `json:"updatedAt,omitempty" form:"updatedAt"`
}
